/* -----------------------------------------------------------------------
 * Demonstration of how to write unit tests for dominion-base
 * Include the following lines in your makefile:
 *
 * unittest2: unittest2.c dominion.o rngs.o
 *      gcc -o testUpdateCoins -g  unittest2.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include "rngs.h"
int main() {
	//testing villageCard
	struct gameState G;
	int numPlayer = 2;
	int seed = 2;
	int player = 0;//just player 0 for now
	int k[10] = {adventurer, council_room, feast, gardens, mine
		, remodel, smithy, village, baron, great_hall};
	
	
	
//	void villageCard(struct gameState *state, int currentPlayer, int handPos){
//		//+1 Card
//		drawCard(currentPlayer, state);
//		
//		//+2 Actions
//		state->numActions = state->numActions + 2;
//		
//		//discard played card from hand
//		discardCard(handPos, currentPlayer, state, 0);
//	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	initializeGame(numPlayer, k, seed, &G); // initialize a new game, deciding later if this is necessary
	int coin_bonus=0;
	int startingDeckCount = G.deckCount[player];
	int startingHandCount = G.handCount[player];
	int startingNumActions = G.numActions;
	
	int handPos = 0;
	//printf("Number of actions: %d\n",startingNumActions);	
	//after effect, player should have one removed from discard pile, have one added to hand (and taken away, so the same amount), and have
	//3 actions available (since decremented in another fxn)
	
	cardEffect(village,0,0,0,&G,handPos,&coin_bonus);
	//printf("Number of actions: %d\n",G.numActions);	
	if ((G.deckCount[player]==(startingDeckCount - 1)) && 
			(G.handCount[player]==(startingHandCount)) &&
			(G.numActions==(startingNumActions+2)) //playCard is where numActions is decremented, so this will return the +2 without decrementing the card used
			)  {
		printf("Passed basic card test\n");
	}
	else{
		printf("Failed basic card test\n");
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////////

	
	//what happens if there are no cards to draw from in draw pile or discard pile?
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	initializeGame(numPlayer, k, seed, &G); // initialize a new game, deciding later if this is necessary
	G.deckCount[player]=0;//remove cards from deck
	startingDeckCount = G.deckCount[player];
	startingHandCount = G.handCount[player];
	startingNumActions = G.numActions;
	//printf("Number of actions: %d\n",startingNumActions);
	//printf("DeckCount: %d\n",G.deckCount[player]);
	//printf("handCount: %d\n",G.handCount[player]);
	cardEffect(village,0,0,0,&G,handPos,&coin_bonus);
	//printf("Number of actions: %d\n",G.numActions);
	//printf("DeckCount: %d\n",G.deckCount[player]);
	//printf("handCount: %d\n",G.handCount[player]);

	//no cards to draw, so should simply remove the card played, add to the played card count, and leave the deck count at zero
	if (
			(G.deckCount[player]==(startingDeckCount)) && 
			(G.handCount[player]==(startingHandCount-1)) && //minus one because we played a card, yet did not have a card to return to our hand
			(G.numActions==(startingNumActions+2)) //playCard is where numActions is decremented, so this will return the +2 without decrementing the card used
			)  {
		
		printf("Passed no cards left test\n");
	}
	else{
		printf("Failed no cards left test\n");
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	//what happens if there are no cards to draw from in draw pile, but there are cards in the discard pile?
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	initializeGame(numPlayer, k, seed, &G); // initialize a new game, deciding later if this is necessary
	G.deckCount[player]=0;//remove cards from deck
	G.discardCount[player]=10;
	startingDeckCount = G.deckCount[player];
	startingHandCount = G.handCount[player];
	startingNumActions = G.numActions;

	
	cardEffect(village,0,0,0,&G,handPos,&coin_bonus);

	
	//no cards to draw, but discard pile has some. that should be shuffled and returned to deck, then card should work properly
	if (
			(G.deckCount[player]==9) && 
			(G.handCount[player]==(startingHandCount)) && //we used a card and then returned a card
			(G.numActions==(startingNumActions+2))&&  //playCard is where numActions is decremented, so this will return the +2 without decrementing the card used
			(G.discardCount[player]==0)
			)  {
		
		printf("Passed reshuffle discarded cards into empty deck test\n");
	}
	else{
		printf("Failed reshuffle discarded cards into empty deck test\n");
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////////

	
	return 0;
}
